
//注册时发送验证码
function register(){
    var phone = $('#phone').val();
    var data = {phone:phone};
    Send(data);
}
//发送兑换码
function convert(){
    var phone = $("#phone").val();
    var data_con = {phone:phone};
    Send_con(data_con);
}
//发送管理员提示短信
function inform() {

    var phone = $("#phone").val();
    var data_hint = {phone:phone};
    // alert('saaeraaaaaf');
    Send_hint(data_hint);
}
//重置密码时发送验证码
function Password(){

}
//更换绑定手机
function binding(){

}
//发送验证码
function Send(data){

    $.ajax({
        url:'/client/registerPhone',
        data:data,
        type:'GET',
        async:false,
        dataType:'json',
        success:function(res){
            console.log(res);
            if("undefined" == typeof res.result){
                //发送失败
                if(res.code == 15){
                    //手机号不合法
                    layer.msg(res.sub_msg);
                }else if(res.code == 15) {
                    layer.msg('手机号不合法');
                }else{
                    layer.msg('发送失败');
                }
            }else{
                //发送成功
                var countdown = 5;
                var obj = $("#btnreg");
                settime(obj,countdown);
            }
        },
        error:function(){
            layer.msg('error');
        }
    });
}

// 发送兑换码
function Send_con(data){
    $.ajax({
        url:'/client/convertPhone',
        // url:'/client/registerPhone',
        data:data,
        type:'GET',
        async:false,
        dataType:'json',
        success:function (res) {
            console.log(res);
            if('undefined' == typeof res.result) {
                //发送失败
                if(res.code == 15) {
                    //手机号不合法
                    layer.msg('手机号不合法');
                }
                else {
                    layer.msg('发送失败');
                }
            }
            else{
                var countdown = 5;
                var obj = $("#pvc");
                settime(obj,countdown);
            }
        },
        error:function() {
            layer.msg('error12344');
        }
    });
}

// 发送管理员提示短信
function Send_hint(data) {
    console.log(data);
    $.ajax({
        url: '/admin/hintPhone',
        // url:'/client/registerPhone',
        data: data,
        type: 'GET',
        async: false,
        dataType: 'json',
        success: function (res) {
            console.log(res);
            if ('undefined' == typeof res.result) {
                //发送失败
                if (res.code == 15) {
                    //手机号不合法
                    layer.msg('手机号不合法');
                }
                else {
                    layer.msg('发送失败');
                }
            }
            else {
                var countdown = 5;
                var obj = $("#hint");
                settime(obj, countdown);
            }
        },
        error: function () {
            layer.msg('error1234sas');
        }
    });
}

//倒计时
function settime(obj,countdown) { //发送验证码倒计时
    if (countdown == 0) {
        obj.attr('disabled',false);
        obj.css('color',"#000");
        //obj.removeattr("disabled");
        obj.val("重新发送");
        countdown = 5;
        return;
    } else {
        obj.attr({disabled:true});
        obj.css('color',"#dbdbdb");
        obj.val("重新发送(" + countdown + ")");
        countdown--;
    }
    setTimeout(function() {
            settime(obj,countdown) }
        ,1000)
}